﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lm.Common.ExtensionMethods
{
    public static class DateTimeExt
    {
        public static DateTime FirstDayInMonth(this DateTime dt)
        {
            return new DateTime(dt.Year, dt.Month, 1);
        }
        public static DateTime LastDayInMonth(this DateTime dt)
        {
            return new DateTime(dt.Year + (dt.Month == 12 ? 1 : 0), dt.Month == 12 ? 1 : dt.Month + 1, 1).AddDays(-1);
        }
        public static int GetDayOfWeek(this DateTime dateTime)
        {
            switch (dateTime.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    { return 1; }
                case DayOfWeek.Tuesday:
                    { return 2; }
                case DayOfWeek.Wednesday:
                    { return 3; }
                case DayOfWeek.Thursday:
                    { return 4; }
                case DayOfWeek.Friday:
                    { return 5; }
                case DayOfWeek.Saturday:
                    { return 6; }
                case DayOfWeek.Sunday:
                    { return 7; }
                default:
                    { return -1; }
            }
        }

        public static Time GetTimePart(this DateTime dateTime)
        {
            return new Time(dateTime.Hour, dateTime.Minute, dateTime.Second);
        }

        public static DateTime GetDatePart(this DateTime dateTime)
        {
            return dateTime.ToShortDateString().ToDatetime();
        }
    }
}
